<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>WebSockettest1</title>

</head>
<body>
    <input type="text" id="input">
    <button type="submit"  onclick="send()">提交</button>

    <script>
        webSocketUrl="ws://"+location.host+"/test1";
        let webSocket = new WebSocket(webSocketUrl);
        webSocket.onopen = function(){
            console.log("连接启动");
        }
        webSocket.console.error=function(){
            console.log("连接异常");
        }
        webSocket.onmessage = function(e){
            console.log("连接消息"+e.data);
        }
        webSocket.onclose = function(){
            console.log("链接关闭");
        }
        function send (){
            
            webSocket.send(document.querySelector('input').value);
            console.log("发送websocket")
        }
        
    </script>
</body>
</html>